

package org.t2.design.module.autogen;


public abstract class LanguageAutoAbstractTable<T extends LanguageAutoAbstractTable.LanguageAutoCfg> extends org.gaming.design.loader.DesignCache<T> {

	@Override
	public final String fileName() {
		return "LanguageAuto";
	}
	
	
	protected java.util.Map<String, T> langIdIndex;
	
	/**
	 * 从索引中获取对象，获取不到会抛异常
	 */
	public final T getInLangIdIndex(
		String langId
	) {
		String key = "" + langId;
		T t = langIdIndex.get(key);
		if(t == null) {
			throw new org.gaming.design.exception.DesignNotFoundException("LanguageAutoTable when getInLangIdIndex", key);
		}
		return t;
	}
	
	/**
	 * 从索引中查找对象，获取不到会返回null
	 */
	public final T findInLangIdIndex(
		String langId
	) {
		String key = "" + langId;
		return langIdIndex.get(key);
	}
	
	/**
	 * 加载langIdIndex索引
	 */
	private final void loadLangIdIndex() {
		java.util.Map<String, T> langIdIndex = new java.util.HashMap<>();
		for(T data : all()) {
			String[] keys = new String[] {
				String.valueOf(data.getLangId()),
			};
			String key = String.join("_", keys);
			if(langIdIndex.containsKey(key)) {
				logger.error("{} found duplicate key {} in index {}", fileName(), key, langIdIndex);
				super.hasError = true;
			}
			langIdIndex.put(key, data);
		}
		this.langIdIndex = langIdIndex;
	}
	
	
	
	@Override
	protected final void loadAutoGenerate() {
		//加载索引
		loadLangIdIndex();
	
		
	}
	
	public static class LanguageAutoCfg {
		//语言ID
		protected String langId;
		/**
		 * get语言ID
		 */
		public String getLangId() {
			return langId;
		}
		//简体中文
		protected String cn;
		/**
		 * get简体中文
		 */
		public String getCn() {
			return cn;
		}
	}

}